<template>
  <view>
  <!-- 登录提示 -->
  <uni-popup ref="popup" type="dialog" :mask-click="maskClick">
    <view class="uni-flex">
      <login :onWxLogin="login"></login>
    </view>
  </uni-popup>
    <WxMpLogin ref="wxMpLogin"></WxMpLogin>
  </view>
</template>

<script>

import WxMpLogin from './WxMpLogin.vue'
import {mapState} from "vuex";
// 登录确认弹层
	export default {
    components:{WxMpLogin},
    computed: {
      ...mapState([
        'hasLogin'
      ])
    },
	  props: {
	    // 自动提示
	    autoPopup: {
	      type: Boolean,
        default: false
      },
      // 蒙版点击是否关闭弹窗
      maskClick: {
        type: Boolean,
        default: true
      }
    },
		data() {
			return {
				
			}
		},
    mounted(){
      // 没有登录自动提示登录
      if (this.autoPopup && !this.hasLogin) {
        this.open()
      }
    },
		methods: {
			open(){
        this.$refs.popup.open()
      },
      close(){
        this.$refs.popup.close()
      },
      login(){
        // 跳转到统一登录而进行登录
        this.$refs.wxMpLogin.wxLogin()
      },
      // 获取当前页面地址
      getCurrentPageUrl() {
        let pages = getCurrentPages() //获取加载的页面
        let currentPage = pages[pages.length - 1] //获取当前页面的对象
        let url = currentPage.route //当前页面url
        let options = currentPage.options //如果要获取url中所带的参数可以查看options
        console.log(options)
        //参数多时通过&拼接url的参数
         let urlWithArgs = url + '?'
         for (let key in options) {
           let value = options[key]
           urlWithArgs += key + '=' + value + '&'
         }
         urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)

        return `/${urlWithArgs}`
      }
		}
	}
</script>

<style>

</style>
